package com.eipc;

import java.util.ArrayList;
import org.androidpn.sdk.Constants;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
import com.eipc.event.OnFetchOtherFinishedListener;
import com.eipc.model.Game;
import com.eipc.model.News;
import com.eipc.model.SerInfoResponse;
import com.eipc.model.Weather;
import com.eipc.util.DBHelper;
import com.eipc.util.HttpManager;

public class FetchOtherTask extends AsyncTask<Integer, Void, Void> {
	private ArrayList<News> news = new ArrayList<News>();
	private Weather weather;
	private Game game;
	private DBHelper mDB;
	private OnFetchOtherFinishedListener listener;
	private Context mContext;
	private SerInfoResponse gameSir;
	
	public FetchOtherTask(Context context,DBHelper db,OnFetchOtherFinishedListener listener){
		mContext = context;
		mDB = db;
		this.listener = listener;
	}
	
	@Override
	protected Void doInBackground(Integer... params) {
		try{
			weather = mDB.queryWeather();
			news = mDB.getTenNews();
			if(params!=null&&params.length>0){
				SharedPreferences sdkPreferences = mContext.getSharedPreferences(Constants.SDK_PREFERENCES, Context.MODE_PRIVATE);
				String mobileID = sdkPreferences.getString(Constants.XMPP_USERNAME,"");
				gameSir = HttpManager.execSerSql(mContext.getString(R.string.url_exec_serSql),mobileID,"match_scroe",Constants.LOAD_MODEL_GAME);
				game = (Game)gameSir.os[0];//mDB.getNewScore(params[0]);
			}
		}catch(Exception e){
            Log.e(this.getClass().getName(),"line 35 ",e);			
		}
		return null;
	}
	
	@Override
	protected void onPostExecute(Void result) {
		super.onPostExecute(result);
		if(listener!=null) listener.OnFinished(news, game, weather);
	}
}
